package com.rjwh.dingdong.client.activity.more;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.aishua.lib.utils.AsAppUtils;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.activity.BaseActivity;
import com.rjwh.dingdong.client.activity.loginregist.ThirdPartyLoginActivity;
import com.rjwh.dingdong.client.activity.webbrowser.WebActivity;
import com.rjwh.dingdong.client.application.MyApplication;
import com.rjwh.dingdong.client.constant.LocalConstant;
import com.rjwh.dingdong.client.service.AppUpgradeServer;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Kay
 * @ClassName MoreAboutUsActivity
 * @Description 个人中心->关于丁冬宝贝
 * @date 2016-7-13
 * @history 2016-7-13 author: description:
 */
public class MoreAboutUsActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.app_bar_layout)
    AppBarLayout appBarLayout;
    @BindView(R.id.about_us_version_tv)
    TextView aboutUsVersionTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_about_us_layout);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        initToolbarHelper();
        aboutUsVersionTv.setText("v" + AsAppUtils.getVersionName(this));
    }

    private void initToolbarHelper() {
        this.setSupportActionBar(this.toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setTitle(getResources().getString(R.string.more_about_us));
        }
        getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }

    @OnClick({R.id.about_us_version_updata_root, R.id.about_us_function_introduction_root, R.id.more_feedback_root})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.about_us_version_updata_root:
                // 检测更新
                AppUpgradeServer.checkUpdata(this, true);
                break;
            case R.id.about_us_function_introduction_root:
                // 产品介绍
                WebActivity.startActivity(this, LocalConstant.PRODUCT_INTRODUCTION);
                break;
            case R.id.more_feedback_root:
                if (MyApplication.spUtil.getBoolPreferenceByParamName(this, LocalConstant.SP_IS_LOGINED)) {
                    startActivity(new Intent(this, MoreFeedBackActivity.class));
                } else {
                    ThirdPartyLoginActivity.startActivity(this);
                }
                break;
        }
    }

}
